# encoding: utf-8 
'''
Created on 2018-6-13
description: 配置读取助手类
@author: zhujianhua
'''
import re
import traceback  

class ConfigReader:
    #默认配置文件路径
    filePath = './etc/mon.cfg'
    #配置字典
    configDict = {}
    
    def __init__(self,filePath):
        self.filePath = filePath
        self._read()
        return
    
    
    def _read(self):
        try:
            reader = open(self.filePath, 'r', encoding='UTF-8')
            lines = reader.readlines()
            
            for line in lines:
                line = line.strip()#除去前后空字符串
                if re.compile('\#|^\\[\\w*\\]$').match(line) or '' == line: #跳过以#开头的注释，[]中括号的内容和空行
                    continue
                else:   
                    splitStr = line.split('=')
                    self.configDict[splitStr[0]] = splitStr[1]
        except:
            traceback.print_exc()
        finally:
            reader.close()
            
            
            
    #获取配置信息        
    def get(self,key):
        return self.configDict[key]
